package com.tebiecloud.yunst.server.service.impl;

import com.tebiecloud.yunst.client.model.entity.YunAgentPay;
import com.tebiecloud.yunst.server.mapper.YunAgentPayMapper;
import com.tebiecloud.yunst.server.service.YunAgentPayService;
import com.tebiecloud.common.mybatis.base.service.impl.BaseServiceImpl;
import com.tebiecloud.yunst.server.yunstservice.YunStService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 *  服务实现类
 * @author tebie
 * @date 2019-09-07
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class YunAgentPayServiceImpl extends BaseServiceImpl<YunAgentPayMapper, YunAgentPay> implements YunAgentPayService {

    @Value("tebiecloud.yunst.backUrl")
    private String backUrl;

    @Autowired
    YunStService yunStService;

    @Autowired
    YunAgentPayMapper yunAgentPayMapper;

    @Override
    public Map<String, Object> applicationTransfer(String bizUserId, Long amount) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        Map<String, String> map = yunStService.applicationTransfer(bizUserId,amount);
        if(map.get("status").equals("OK")){
            YunAgentPay yunAgentPay = new YunAgentPay();
            yunAgentPay.setRecieverId(bizUserId);
            yunAgentPay.setBizOrderNo(map.get("bizTransferNo"));
            yunAgentPay.setAmount(amount.intValue());
            yunAgentPay.setPayStatus(1);
            yunAgentPay.setRemark(map.get("res"));
            yunAgentPayMapper.insert(yunAgentPay);
            resultMap.put("status","OK");
            resultMap.put("yunAgentPay",yunAgentPay);
        }else{
            resultMap.put("status","error");
            resultMap.put("message",map.get("message"));
        }
        return resultMap;
    }
}
